package server;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.Socket;

public class ChatThread extends Thread{
    private Socket socket;

    public ChatThread(Socket socket){
        this.socket = socket;
    }

    public void out(String out) {
        try {
            socket.getOutputStream().write(out.getBytes("UTF-8"));
        } catch (Exception e) {
        }
    }

    public void run() {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream(), "UTF-8"));
            String line = "";
            while ((line = br.readLine()) != null) {
                System.out.println(line);
                ChatThreadManager.getChartManager().publish(this, line);
            }
            br.close();
        } catch (Exception e) {
            // TODO: handle exception
        }
    }
}
